import { WidgetClass } from "./widget";
export class WidgetInput extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const { ports,UI } = options;
    if (UI) {
      this.UI.data = UI.data
    } else {
      this.UI.data = {
      obscureText: false, // text/password
      placeholder: "请输入文本内容",
      systemKeyboard: false,//使用系统键盘的bool值配置
      };
    }
    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultState(options = {}) {
    const superState = super.assembleDefaultState(options);
    return {
      ...superState,
      values: {
        text: "",
      },
    };
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      ...superState,
      values: [
      ...superState.values,
        {
          name: "文本",
          key: "text",
          type: "string",
          value: "",
        },
        {
          name: "光标位置",
          key: "selection",
          type: "int",
          value: 0,
        },
      ],
      events: [
        {
          name: "开始输入事件",
          key: `inputStart-${this.id}`,
          eventType: "inputStart",
          type: "event",
          action: [],
        },
        {
          name: "文本值改变",
          key: `valueChange-${this.id}`,
          eventType: "valueChange",
          type: "event",
          action: [],
        },
        {
          name: "长按事件",
          key: `longPress-${this.id}`,
          eventType: "longPress",
          type: "event",
          value: {
            time: 1 //长按触发时间(秒)
          },
          action: [],
        },
      ],
    };
  }
}
